<div class="colRmargin page-login">
<h1 class="guide">编辑文档</h1>
<?php echo form_open('user/mydocs/edit',  array('name' => 'postBuyRequestForm', 'id' => 'postBuyRequestForm','onSubmit'=>'return checkdata();','class'=>'ui-form ui-form-horizontal ui-form-grouping')); ?>
<?php 
if(!empty($edit_read)) {
	foreach($edit_read as $k => $v) {
?>
<fieldset class="ui-form-group" id="product-basic">
	<legend class="br-group-title">文档编号：<?php echo $v['rtid']; ?></legend>
	<div class="ui-form-item first">
            <label for="subject" class="ui-form-label"><m class="ui-form-required">*</m>标题/名称</label>
            <div class="ui-form-control">
                <input type="text" value="<?php echo $v['title']; ?>" name="title[]" class="ui-textfield ui-textfield-system ui-control-xl" maxlength="80" id="title" >
                <div class="suggest-wrapper" id="suggest-wrapper"></div>
            </div>
    </div>
    <div class="ui-form-item" id="detail">
		<label for="detailTextarea" class="ui-form-label">
            <span class="J-label">摘要:<br />（如没有填，则自动截取文档前125字）</span>
		</label>
		<div class="ui-form-control">
			<textarea name="synopsis[]" class="ui-textfield ui-textfield-system multiple ui-control-xl br-textarea" id="synopsis"><?php echo $v['synopsis']; ?></textarea>
			<div class="remaining-number" id="remainingNumber"><span class="remark-alert" id="countDown">请限制在250</span> 个字符或125汉字</div>
		</div>
	</div>
    <div class="ui-form-item">
		<label for="quantityAnnual" class="ui-form-label">封面图片:</label>
		<div class="ui-form-control">
			<input type="text" id="pic<?php echo $v['rtid']; ?>" value="<?php echo $v['pic_host'] . $v['pic']; ?>" name="pic[]" class="ui-textfield ui-textfield-system ui-control-m" maxlength="250" /> 
			<input type="button" id="image<?php echo $v['rtid']; ?>" value="上传/选择图片" />　<span class="remark-alert" id="countDown">图片最大200K[</span>
			<span class="remark-alert" id="countDown">不填则系统自动生成封面]</span>
		</div>
	</div>
	<div class="ui-form-item" id="order-quantity">
		<label for="quantity" class="ui-form-label"><m class="ui-form-required">*</m><span class="J-label">选择类别:</span></label>
		<div class="ui-form-control">
			<select name="channel[]" size="10" class="ui-dropdown ui-dropdown-system" id="channel" style="z-index: 0; height:auto;" onchange="showAttribute(<?php echo $v['cid']; ?>, <?php echo $k; ?>)" >
            <?php 
				if(!empty($channel)) {
					foreach($channel as $kk => $vv) {
						$disable = $depth = $selected = '';
				 		if($vv['parent'] == 0 && !empty($vv['children'])) $disable = 'disabled="disabled"';
						if($v['cid'] == $vv['cid']) $selected = 'selected="selected"';
						for($i = 0; $i < $vv['depth']; $i++) {
							$depth .= '﹣';
						}
						echo '<option '.$selected.' '.$disable.' value="'.$vv['cid'].'">'.$depth.$vv['title'].'('.$vv['en_title'].')</option>';
					}
				}
			?>
			</select>
		</div>
	</div>
    <div class="ui-form-item first">
            <label for="subject" class="ui-form-label"><m class="ui-form-required"></m>售价:</label>
            <div class="ui-form-control">
                <input name="price[]" type="text" class="ui-textfield ui-textfield-system ui-control-s" id="price" value="<?php echo $v['price']; ?>" size="10" maxlength="10" >
                <div class="suggest-wrapper" id="suggest-wrapper"></div>
      </div>
    </div>
    <div class="ui-form-item" id="detail">
		<label for="detailTextarea" class="ui-form-label">
			<m class="ui-form-required"></m>
            <span class="J-label">详细介绍:</span>
		</label>
		<div class="ui-form-control">
        	<input type="hidden" value="<?php echo $v['rtid']; ?>" name="editid[]"  />
			<textarea name="desc[]" class="ui-textfield ui-textfield-system multiple ui-control-xl br-textarea" id="desc"><?php echo $v['desc']; ?></textarea>
			<div class="remaining-number" id="remainingNumber"><span class="remark-alert" id="countDown">请限制在1000</span> 个字符或500汉字</div>
		</div>
	</div>
    <div class="ui-form-item"><label class="ui-form-label">多选Tag标签</label>
    	<div class="ui-form-control" id="property"> 
		<?php if(!empty($property)) { 
				 foreach($property as $kk => $vv) {
					 $checked = '';
					 if(isset($edit_read_property[$vv['pid']])) $checked = 'checked="checked"';
					 echo '<input '.$checked.' type="checkbox" value="'.$vv['pid'].'" name="property['.$k.']['.$vv['pid'].']" >'
				    	  .'<span class="remark-alert">'.$vv['title'].'&nbsp;&nbsp;&nbsp;</span> <span>&nbsp;&nbsp;</span>';}} ?>
        </div>
    </div>
    <div class="ui-form-item" id="attribute">
    <?php if(!empty($edit_read_attr)) {
		   foreach($edit_read_attr as $kk => $vv) {
			if($attribute_title[$vv['aid']]['is_father'] == '1') {
	    ?>	
   		<div class="ui-form-control"><div id="remainingNumber" class="remaining-number">
        	<span id="countDown" class="remark-alert"><?php echo $attribute_title[$vv['aid']]['title'] ?></span></div>
            <input type="hidden" value="<?php echo $vv['values'] ?>" name="attribute[<?php echo $k; ?>][<?php echo $vv['aid'] ?>]" >
        </div>
        <?php } else {?>
		<label class="ui-form-label"><?php echo $attribute_title[$vv['aid']]['title']; ?>：</label>
		<div class="ui-form-control"><input type="text" value="<?php echo $vv['values']; ?>" name="attribute[<?php echo $k; ?>][<?php echo $vv['aid']; ?>]" class="ui-textfield ui-textfield-system ui-control-m" maxlength="50" ></div>
    <?php        }}}?>
	</div>
</fieldset>
<br />
<?php
	}
} else {
	echo '<div class="ui-form-item"><label for="detailTextarea" class="ui-form-label"></label></div>';	
}
?>

	<div style="padding-left: 225px; padding-top:10px; " id="check-rules-div">
		<span><span style="color: #333333;"></span></span>
	</div>
		<div class="ui-form-action">
        	<input type="hidden" name="__H" value="update" />
            <input type="hidden" name="next_rtid" value="<?php echo $next_rtid;?>" />
        <?php if(empty($message)) { ?> 
        	<input type="submit" class="ui-button ui-button-primary ui-button-medium" value="保存修改并递交审" id="form-submit-btn">
        <?php } else {?>
			<input type="button" onclick="location.href='<?php echo $message_edit_url;?>'" class="ui-button ui-button-primary ui-button-medium" value="返回修改" id="form-submit-btn">
			<?php if(!empty($message_edit_next_url)) {?>
            <input type="button" onclick="location.href='<?php echo $message_edit_next_url;?>'" class="ui-button ui-button-primary ui-button-medium" value="编辑下一个" id="form-submit-btn">
			<?php }?>
		<?php }?>
    </div>      
<?php echo form_close();?>
</div>
<script language="javascript">
function checkdata() {
	var obj = $('select[name="channel[]"]');
	var input = $('input[name="title[]"]');
	var resule = true;
	obj.each(function(index, element) {
		if(obj.eq(index).val() == '' || obj.eq(index).val() == null) {
			showMsg('类别不能为空！请选择类别后提交！');
			resule = false;
		}
	});
	input.each(function(index, element) {
		if(input.eq(index).val() == '' || input.eq(index).val() == null) {
			showMsg('标题/名称不能为空！请填写后提交！');
			resule = false;
		}
	});
	return resule;
}
KindEditor.ready(function(K) {
	var editor = K.editor({
		uploadJson       : '<?php echo $ulpoad_url; ?>',
		fileManagerJson  : '<?php echo $this->config->base_url('user/userimgmanager');?>',					
		allowFileManager : true,
		formatUploadUrl  : false,
		allowMediaUpload : false
	});
	<?php
	if(!empty($edit_read)) {
	foreach($edit_read as $k => $v) {
	?>
	K('#image<?php echo $v['rtid']; ?>').click(function() {
		editor.loadPlugin('image', function() {
			editor.plugin.imageDialog({
				imageUrl : K('#pic<?php echo $v['rtid']; ?>').val(),
				clickFn : function(url, title, width, height, border, align) {
					K('#pic<?php echo $v['rtid']; ?>').val(url);
					editor.hideDialog();
				}
			});
		});
	});
	<?php }}?>
});

</script>
<script language="javascript">
var property_div = attribute_div = '';
function showAttribute(src_cid, k) {
		var cid = $('#channel').val();
		var html = '';
		if(src_cid != cid ) {
			if(property_div == '') {property_div = $('#property').html();}
			if(attribute_div == '') {attribute_div = $('#attribute').html();}
		} else {
			$('#property').html(property_div);$('#attribute').html(attribute_div);return;
		}
		if(cid > 0) {
			var url = "<?php echo $this->config->base_url('user/attribute?cid=');?>" + cid;
			$.get(url, function(data){
			 html = writeAttribute(data.attribute, k);
			 $('#attribute').html(html);
			 html = writeProperty(data.property, k);
			 $('#property').html(html);
			},'json');
		}
}
function writeProperty(property, k) {
	var html = '';
	for(val in property) {
		html =  html +'<input type="checkbox" value="'+property[val].pid+'" name="property['+k+']['+property[val].pid+']" >'
				+ '<span class="remark-alert">' + property[val].title + '&nbsp;&nbsp;&nbsp;</span> <span>&nbsp;&nbsp;</span>';
	}
	return html;
}
function writeAttribute(attribute, k) {
	var html = '';
	for(val in attribute) {
		if(attribute[val].is_father == '1') {
		html =  html + '<div class="ui-form-control"><div id="remainingNumber" class="remaining-number">'
		        +'<span id="countDown" class="remark-alert">'+attribute[val].title+'</span></div></div>'
				+'<input type="hidden" value="" name="attribute['+k+']['+attribute[val].aid+']" >';
		} else {
		html =  html + '<label class="ui-form-label">'+attribute[val].title+'：</label>'
			    + '<div class="ui-form-control">'
				+ '<input type="text" value="" name="attribute['+k+']['+attribute[val].aid+']" class="ui-textfield ui-textfield-system ui-control-m" maxlength="50" >'
				+ '</div>';
		}
	}
	return html;
	/*<label class="ui-form-label">发行出版社：</label><div class="ui-form-control"><input type="text" value="" name="" class="ui-textfield ui-textfield-system ui-control-m" maxlength="50" id="quantityAnnual"></div>
<label class="ui-form-label">作者：</label>
<div class="ui-form-control"><input type="text" value="" name="" class="ui-textfield ui-textfield-system ui-control-m" maxlength="50" id="quantityAnnual"></div>
</div>';*/

}
</script>